<template>
  <div class="category">
    <el-card>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="一级分类">
          <el-select
            placeholder="请选择一级分类"
            v-model="CategoryStore.c1Id"
            @change="handler"
          >
            <el-option
              v-for="item in CategoryStore.c1Arr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="二级分类">
          <el-select
            placeholder="请选择二级分类"
            v-model="CategoryStore.c2Id"
            @change="handler1"
          >
            <el-option
              v-for="item in CategoryStore.c2Arr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="三级分类">
          <el-select placeholder="请选择三级分类" v-model="CategoryStore.c3Id">
            <el-option
              v-for="item in CategoryStore.c3Arr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script lang="ts" setup>
import { onMounted } from 'vue'
import { useCategoryStore } from '@/store/modules/category'
const CategoryStore = useCategoryStore()
onMounted(() => {
  CategoryStore.getC1()
})
const handler = () => {
  //需要将二级、三级分类的数据清空
  CategoryStore.c2Id = ''
  CategoryStore.c3Arr = []
  CategoryStore.c3Id = ''
  CategoryStore.getC2()
}
const handler1 = () => {
  // console.log(CategoryStore.c2Id);
  CategoryStore.c3Id = ''
  CategoryStore.getC3()
}
</script>
<style scope>
.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.demo-form-inline .el-select {
  --el-select-width: 220px;
}
</style>
